package com.dlyk.web;

import com.dlyk.model.TActivityRemark;
import com.dlyk.model.TUser;
import com.dlyk.query.ActivityQuery;
import com.dlyk.query.ActivityRemarkQuery;
import com.dlyk.result.R;
import com.dlyk.service.ActivityRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: ajie
 * @date: 2024/7/23 18:09:23
 * @version: 1.0
 */
@RestController
public class ActivityRemarkController {

    @Resource
    private ActivityRemarkService activityRemarkService;

    /**
     * @description: 新增活动备注 
     * @params: [activityRemarkQuery, token]       
     * @return: 
     * @author: ajie
     * @date: 2024/7/23 20:40
     */
    @PostMapping("/api/activity/remark")
    public R addActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery,
                               @RequestHeader("Authorization") String token) {
        activityRemarkQuery.setToken(token);
        int save = activityRemarkService.saveActivityRemark(activityRemarkQuery);
        return save >= 1 ? R.OK() : R.FAIL();
    }
    
    /**
     * @description: 查询活动备注列表
     * @params: [current]       
     * @return: 
     * @author: ajie
     * @date: 2024/7/23 20:39
     */
    @GetMapping("/api/activity/remark")
    public R activityRemarkPage(@RequestParam(value = "current",required = false) Integer current,
                                @RequestParam(value = "activityId") Integer activityId){
        ActivityRemarkQuery activityRemarkQuery = new ActivityRemarkQuery();
        activityRemarkQuery.setActivityId(activityId);
        if (current == null){
            current = 1;
        }
        PageInfo<TActivityRemark> pageInfo = activityRemarkService.getActivityRemarkByPage(current,activityRemarkQuery);
        return R.OK(pageInfo);
    }

    /**
     * @description: 根据id查询活动备注 
     * @params: [id]       
     * @return: 
     * @author: ajie
     * @date: 2024/7/24 15:28
     */
    @GetMapping("/api/activity/remark/{id}")
    public R getActivityRemarkById(@PathVariable(value = "id") Integer id ){

        TActivityRemark tActivityRemark = activityRemarkService.getActivityRemarkById(id);
        return R.OK(tActivityRemark);
    }

    /**
     * @description: 编辑活动备注
     * @params: [activityRemarkQuery, token]
     * @return:
     * @author: ajie
     * @date: 2024/7/24 16:10
     */
    @PutMapping("/api/activity/remark")
    public R editActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery,
                                @RequestHeader("Authorization") String token) {
        activityRemarkQuery.setToken(token);
        int update = activityRemarkService.updateActivityRemark(activityRemarkQuery);
        return update >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * @description: 根据id删除活动备注
     * @params: [id]
     * @return:
     * @author: ajie
     * @date: 2024/7/28 20:28
     */
    @DeleteMapping("/api/activity/remark/{id}")
    public R delActivityRemark(@PathVariable(value = "id") Integer id){
        int del = activityRemarkService.delActivityRemarkById(id);
        return del >= 1 ? R.OK() : R.FAIL();
    }
}
